Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environments #145

Merged
merged 11 commits into from
Mar 21, 2024
Merged

Environments #145

merged 11 commits into from
Mar 21, 2024

Conversation

JoeyT1994
Copy link
Contributor

@JoeyT1994 JoeyT1994 commented Mar 18, 2024

This PR adds the functionality environment(tn::AbstractITensorNetwork, verbs::Vector) to the codebase with returns the environment (related to the derivative) of an ITensorNetwork with respect to some subset of its vertices.

Algorithms are defined for getting the environments/derivates which currently include either exact contraction or belief propagation. This new functionality has been hooked to interface environment(f::AbstractFormNetwork, state_vertices::Vector).

Testing it added for this within test/test_forms.jl

@mtfishman
Copy link
Member

My thinking on derivative(f::AbstractFormNetwork, state_vertices::Vector) is that for a form, you can only take the derivative with respect to the state vertices, so a separate function derivative_state wouldn't be necessary.

src/derivative.jl Outdated Show resolved Hide resolved
test/test_forms.jl Outdated Show resolved Hide resolved
test/test_forms.jl Outdated Show resolved Hide resolved
test/test_forms.jl Outdated Show resolved Hide resolved
src/derivative.jl Outdated Show resolved Hide resolved
@JoeyT1994
Copy link
Contributor Author

JoeyT1994 commented Mar 19, 2024

@mtfishman In terms of derivative(f::AbstractFormNetwork, state_vertices::Vector) instead of derivative_state(f::AbstractFormNetwork, state_vertices::Vector), the issue is that it conflicts with derivative(itn::AbstractITensorNetwork, vertices::Vector) in src/derivative.jl which I want derivative_state to forward to. We have the hierarchy FormNetwork <: AbstractITensorNetwork and so currently that would just create a circular loop.

I was originally defining derivative(itn::AbstractITensorNetwork, vertices::Vector) and having derivative(f::AbstractFormNetwork, state_vertices::Vector) pass to that by calling derivative(itensornetwork(f), vertices(f, state_vertices)) but the logic for building the bp_cache (if it is not defined) is in derivative(itn::AbstractITensorNetwork, vertices::Vector) and I want the default cache (default partitioning) to be different for an AbstractFormNetwork vs an AbstractITensorNetwork`. I.e I have:

default_partitioning(ψ::AbstractITensorNetwork) = group(v -> v, vertices(ψ))
default_partitioning(f::AbstractFormNetwork) = group(v -> state_vertex(f,v), vertices(f))

at the moment so a standard ψ::AbstractITensorNetwork just has simple BP done on it with no partitioning but a f::AbstractFormNetwork will partition itself by the state_vertices by default.

@codecov-commenter
Copy link

codecov-commenter commented Mar 19, 2024

Codecov Report

Attention: Patch coverage is 88.00000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 73.87%. Comparing base (5df202a) to head (9bb5c7a).
Report is 3 commits behind head on main.

Files Patch % Lines
src/caches/beliefpropagationcache.jl 80.00% 3 Missing ⚠️
src/formnetworks/abstractformnetwork.jl 83.33% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #145      +/-   ##
==========================================
+ Coverage   73.61%   73.87%   +0.25%     
==========================================
  Files          71       75       +4     
  Lines        4146     4256     +110     
==========================================
+ Hits         3052     3144      +92     
- Misses       1094     1112      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mtfishman
Copy link
Member

mtfishman commented Mar 19, 2024

Can't you specify a different default partitioning in derivative(f::AbstractFormNetwork, state_vertices::Vector)? That issue seems like something we can circumvent without having to define a new function derivative_state.

@JoeyT1994
Copy link
Contributor Author

Yeah good point: I can make the choice partitioning a kwarg of derivative(Alg::"BP", ...) and have derivative(f::AbstractForm, ...) define that and pass it on

@mtfishman mtfishman changed the title Derivatives Environments Mar 20, 2024
src/environment.jl Outdated Show resolved Hide resolved
src/environment.jl Outdated Show resolved Hide resolved
@mtfishman
Copy link
Member

Looks good, thanks! One more step towards BP-based DMRG/TDVP...

@mtfishman mtfishman merged commit 0477e9d into ITensor:main Mar 21, 2024
7 of 11 checks passed
@JoeyT1994 JoeyT1994 deleted the derivatives branch June 16, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants